﻿#ifndef LISTWIDGETITEM_H
#define LISTWIDGETITEM_H

#include "ElementTreeItem.h"
#include <QListWidgetItem>
class QCPGraph;
class ElementTreeItem;
class ListWidgetItem : public QListWidgetItem
{
public:
    // enum RoleType{

    // };
    ListWidgetItem(const QString &text,ElementTreeItem * treeItem, QListWidget *listview = nullptr);

    ElementTreeItem* elementTreeItem(){
        return mElementTreeItem;
    }

    QCPGraph* graph(){return mGraph;}
    void SetGraph(QCPGraph* graph){mGraph=graph;}

    QVector<double>& xData();
    QVector<double>& yData();
    const QVector<double>& xData() const;
    const QVector<double>& yData() const;
    double xData(int index){
        return mXData[index];
    }
    double yData(int index){
        return mYData[index];
    }

    double A(){return mA;}
    double dt(){return mDT;}
    double B(){return mB;}
    void setA(double num){mA=num;}
    void setDt(double num){mDT=num;}
    void setB(double num){mB=num;}

    double yMaxData(){
        return mElementTreeItem->maxData()*mA+mB;
    }
    double yMinData(){
        return mElementTreeItem->minData()*mA+mB;
    }
    double xMaxData(){
        return mElementTreeItem->parent()->maxData()-mDT;
    }
    double xMinData(){
        return mElementTreeItem->parent()->minData()-mDT;
    }
    int yMaxDataIndex(){
        return mElementTreeItem->maxDataIndex();
    }
    int yMinDataIndex(){
        return mElementTreeItem->minDataIndex();
    }
    int xMaxDataIndex(){
        return mElementTreeItem->parent()->maxDataIndex();
    }
    int xMinDataIndex(){
        return mElementTreeItem->parent()->minDataIndex();
    }

    void updateGraphData();
    QString name();
private:
    double mA=1,mDT=0,mB=0;
    ElementTreeItem* mElementTreeItem;
    QCPGraph* mGraph;
    QVector<double>& mXData;
    QVector<double>& mYData;
    int mStart=0,mEnd=0;
};

#endif // LISTWIDGETITEM_H
